DriverGUI.m 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942
  1. function varargout = DriverGUI(varargin)
  2. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  3. % Configures PLS settings & calls analysis sections to run. %
  4. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  5. % Copyright (C) 2013-2014, Michael J. Cheung
  6. %
  7. % This file is a part of the MEG & PLS Pipeline (MEGPLS). For more
  8. % details, see the documentation included with the software package.
  9. %
  10. % MEGPLS is free software: you can redistribute it and/or modify it under
  11. % the terms of the GNU General Public License version 2 as published by
  12. % the Free Software Foundation. This program is distributed in the hope
  13. % that it will be useful, but WITHOUT ANY WARRANTY; without even the
  14. % implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. % See the GNU General Public License for more details.
  16. %
  17. % You should have received a copy of the GNU General Public License along
  18. % with this program. If not, you can download the license here:
  19. % <http://www.gnu.org/licenses/old-licenses/gpl-2.0>.
  20. % Last Modified by GUIDE v2.5 24-Sep-2014 01:06:42
  21. % Begin initialization code - DO NOT EDIT
  22. gui_Singleton = 1;
  23. gui_State = struct('gui_Name', mfilename, ...
  24. 'gui_Singleton', gui_Singleton, ...
  25. 'gui_OpeningFcn', @DriverGUI_OpeningFcn, ...
  26. 'gui_OutputFcn', @DriverGUI_OutputFcn, ...
  27. 'gui_LayoutFcn', [] , ...
  28. 'gui_Callback', []);
  29. if nargin && ischar(varargin{1})
  30. gui_State.gui_Callback = str2func(varargin{1});
  31. end
  32. if nargout
  33. [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
  34. else
  35. gui_mainfcn(gui_State, varargin{:});
  36. end
  37. % End initialization code - DO NOT EDIT
  38. %--- Executes just before DriverGUI is made visible. ---%
  39. %-------------------------------------------------------%
  40. function DriverGUI_OpeningFcn(hObject, eventdata, handles, varargin)
  41. % This function has no output args, see OutputFcn.
  42. % hObject handle to figure
  43. % eventdata reserved - to be defined in a future version of MATLAB
  44. % handles structure with handles and user data (see GUIDATA)
  45. % varargin command line arguments to DriverGUI (see VARARGIN)
  46. % Choose default command line output for DriverGUI
  47. handles.output = hObject;
  48. % Make sure toolbox paths are added:
  49. [PipelineDir, ~, ~] = fileparts(which('DriverGUI.m'));
  50. addpath(genpath(PipelineDir));
  51. rmpath([PipelineDir,'/DEFAULT_SETTINGS']); % Make sure its calling from AnalysisID
  52. rmpath([PipelineDir,'/TEMPORARY_FIXES']); % Make sure its calling from FT toolbox
  53. CheckToolboxPaths(PipelineDir);
  54. % Initialize variables and default settings:
  55. handles.gui.BuilderMat = [];
  56. handles.gui.ManualTimeIndices = [];
  57. handles.gui.DefaultBrainMask = ...
  58. [PipelineDir,'/MEGPLS_TOOLBOX/Masks_Templates/mask_T1+tlrc.BRIK'];
  59. handles.gui.DefaultROIMask = ...
  60. [PipelineDir,'/MEGPLS_TOOLBOX/Masks_Templates/area_coords_RAI.xls'];
  61. handles.name = [];
  62. handles.time = [];
  63. handles.paths = [];
  64. handles.PLSmat.OrigBuilder = [];
  65. handles.PLSmat.SessionID = [];
  66. handles.PLSmat.name.GroupID = [];
  67. handles.PLSmat.name.SubjID = [];
  68. handles.PLSmat.name.CondID = [];
  69. handles.PLSmat.paths.Afni4D = []; % For PLS datamat input
  70. handles.PLSmat.paths.NormSource = []; % For data-specific mask generation
  71. handles.PLSmat.paths.AnalysisID = [];
  72. handles.PLSmat.time = [];
  73. handles.PLSmat.TimeIndices = []; % Default is epoch, but no builder loaded yet
  74. handles.PLSmat.ManualTimeSelect = 'no';
  75. handles.PLSmat.MaskType = 'BrainMask';
  76. handles.PLSmat.DataSpecificMask = 'yes';
  77. handles.PLSmat.MaskKeepVoxThresh = 0.90; % 90% datasets need to share voxel for it to be included into mask.
  78. handles.PLSmat.BrainMaskFile = handles.gui.DefaultBrainMask;
  79. handles.PLSmat.ROIMaskFile = handles.gui.DefaultROIMask;
  80. handles.PLSmat.ROIBlobSize = [-1:1];
  81. handles.PLSmat.BhvSeedID = [];
  82. handles.PLSmat.BhvFile = [];
  83. handles.PLSmat.SeedFile = [];
  84. handles.PLSmat.SeedBlobSize = [];
  85. handles.PLSrun.NRContrast = [];
  86. handles.PLSrun.NRContrastID = [];
  87. handles.PLSrun.Method = 'MCENT';
  88. handles.PLSrun.SplitHalf = 'no';
  89. handles.PLSrun.SingleBhv = 'no';
  90. handles.PLSrun.KeepDatamat = 'no';
  91. handles.PLSrun.NumPerm = 500;
  92. handles.PLSrun.NumBoot = 500;
  93. handles.PLSrun.NumSplit = 0;
  94. handles.PLSrun.CorrMode = 0;
  95. handles.PLSrun.PermType = 0; % is_struct field
  96. handles.PLSrun.MCentType = 0;
  97. handles.PLSrun.BootType = 'strat';
  98. % Update handles structure
  99. guidata(hObject, handles);
  100. % UIWAIT makes DriverGUI wait for user response (see UIRESUME)
  101. % uiwait(handles.figure1);
  102. %--- Outputs from this function are returned to the command line. ---%
  103. %--------------------------------------------------------------------%
  104. function varargout = DriverGUI_OutputFcn(hObject, eventdata, handles)
  105. % varargout cell array for returning output args (see VARARGOUT);
  106. % hObject handle to figure
  107. % eventdata reserved - to be defined in a future version of MATLAB
  108. % handles structure with handles and user data (see GUIDATA)
  109. % Get default command line output from handles structure
  110. varargout{1} = handles.output;
  111. %=====================================%
  112. % FUNCTIONS FOR LOADING BUILDER .MAT: %
  113. %=====================================%
  114. %--- Executes on button press in ButtonLoadBuilderMat. ---%
  115. %---------------------------------------------------------%
  116. function ButtonLoadBuilderMat_Callback(hObject, eventdata, handles)
  117. [BuilderFile, BuilderPath] = uigetfile('Builder_*.mat',...
  118. 'Select Builder .mat file to load:', 'MultiSelect', 'off');
  119. if BuilderFile == 0
  120. return; % If user cancels
  121. else
  122. handles.gui.BuilderMat = [BuilderPath,BuilderFile];
  123. set(handles.TextboxBuilderMat, 'String', handles.gui.BuilderMat);
  124. end
  125. % Start Waitbox:
  126. WaitBox = StartWaitBox('LOADING BUILDER .MAT FILE:');
  127. % Load selected builder (for GUI purposes):
  128. LoadBuilder = load(handles.gui.BuilderMat);
  129. handles.name = LoadBuilder.name;
  130. handles.time = LoadBuilder.time;
  131. handles.paths = LoadBuilder.paths;
  132. % Reset PLS settings & GUI panels:
  133. handles = ResetPLSmatInputData (handles);
  134. handles = ResetTimeSettings (handles);
  135. handles = ResetMaskSettings (handles);
  136. handles = ResetBehaviorSettings (handles);
  137. handles = ResetPLSrunSettings (handles);
  138. % Load builder settings into PLSmat (for MakePLSmat & PLSrun input):
  139. handles.PLSmat.OrigBuilder = LoadBuilder;
  140. handles.PLSmat.name = LoadBuilder.name;
  141. handles.PLSmat.time = LoadBuilder.time;
  142. handles.PLSmat.paths.Afni4D = LoadBuilder.paths.Afni4DNormSource;
  143. handles.PLSmat.paths.NormSource = LoadBuilder.paths.NormSource;
  144. handles.PLSmat.paths.AnalysisID = LoadBuilder.paths.AnalysisID;
  145. % Reset run section values:
  146. set(handles.CheckboxTimelockAnalysis, 'Value', 0);
  147. set(handles.CheckboxTimelockGrpAvg, 'Value', 0);
  148. set(handles.CheckboxFreqAnalysis, 'Value', 0);
  149. set(handles.CheckboxFreqGrpAvg, 'Value', 0);
  150. set(handles.CheckboxSegmentMRI, 'Value', 0);
  151. set(handles.CheckboxHdmLeadfield, 'Value', 0);
  152. set(handles.CheckboxSourceFilter, 'Value', 0);
  153. set(handles.CheckboxSourceAnalysis, 'Value', 0);
  154. set(handles.CheckboxMakeSourceNifti, 'Value', 0);
  155. set(handles.CheckboxMakeSourceAfni, 'Value', 0);
  156. set(handles.CheckboxNormaliseSource, 'Value', 0);
  157. set(handles.CheckboxMakeNormSrcNifti, 'Value', 0);
  158. set(handles.CheckboxMakeNormSrcAfni, 'Value', 0);
  159. set(handles.CheckboxGroupAvgNormSrc, 'Value', 0);
  160. set(handles.CheckboxMakeGrpAvgNifti, 'Value', 0);
  161. set(handles.CheckboxMakeGrpAvgAfni, 'Value', 0);
  162. set(handles.CheckboxMakePLSmat, 'Value', 0);
  163. set(handles.CheckboxRunPLS, 'Value', 0);
  164. % Enable/disable run section panel:
  165. set(findall(handles.PanelRunTimelockFreq, '-property', 'Enable'), 'Enable', 'on');
  166. set(findall(handles.PanelRunSource, '-property', 'Enable'), 'Enable', 'on');
  167. set(findall(handles.PanelRunPLS, '-property', 'Enable'), 'Enable', 'on');
  168. if ~strcmp(LoadBuilder.gui.MEGdataFiletype, 'Fieldtrip')
  169. set(handles.CheckboxTimelockAnalysis, 'Enable', 'off');
  170. set(handles.CheckboxTimelockGrpAvg, 'Enable', 'off');
  171. set(handles.CheckboxFreqAnalysis, 'Enable', 'off');
  172. set(handles.CheckboxFreqGrpAvg, 'Enable', 'off');
  173. set(handles.CheckboxSegmentMRI, 'Enable', 'off');
  174. set(handles.CheckboxHdmLeadfield, 'Enable', 'off');
  175. set(handles.CheckboxSourceFilter, 'Enable', 'off');
  176. set(handles.CheckboxSourceAnalysis, 'Enable', 'off');
  177. set(handles.CheckboxMakeSourceNifti, 'Enable', 'off');
  178. set(handles.CheckboxNormaliseSource, 'Enable', 'off');
  179. set(handles.CheckboxMakeNormSrcNifti, 'Enable', 'off');
  180. set(handles.CheckboxGroupAvgNormSrc, 'Enable', 'off');
  181. set(handles.CheckboxMakeGrpAvgNifti, 'Enable', 'off');
  182. end
  183. if strcmp(LoadBuilder.gui.MEGdataFiletype, 'AFNI')
  184. set(handles.CheckboxMakeSourceAfni, 'Enable', 'off');
  185. set(handles.CheckboxMakeNormSrcAfni, 'Enable', 'off');
  186. set(handles.CheckboxMakeGrpAvgAfni, 'Enable', 'off');
  187. end
  188. % Update PLS settings & GUI panels:
  189. handles = UpdatePLSmatInputData (handles);
  190. handles = UpdateTimeSettings (handles);
  191. handles = UpdateMaskSettings (handles);
  192. handles = UpdateBehaviorSettings (handles);
  193. handles = UpdatePLSrunSettings (handles);
  194. % Save handles:
  195. guidata(hObject, handles);
  196. close(WaitBox);
  197. %--- Textbox to display selected path of Builder: ---%
  198. %----------------------------------------------------%
  199. function TextboxBuilderMat_Callback(hObject, eventdata, handles)
  200. EnteredText = get(handles.TextboxBuilderMat, 'String');
  201. if ~isequal(EnteredText, handles.gui.BuilderMat)
  202. set(handles.TextboxBuilderMat, 'String', handles.gui.BuilderMat);
  203. msgbox('Note: Use the button to change Builder .mat file.')
  204. end
  205. %=======================================%
  206. % FUNCTIONS FOR SELECTING RUN SECTIONS: %
  207. %=======================================%
  208. %--- Checkboxes for timelock & frequency analysis: ---%
  209. %-----------------------------------------------------%
  210. % --- Executes on button press in CheckboxTimelockAnalysis.
  211. function CheckboxTimelockAnalysis_Callback(hObject, eventdata, handles)
  212. if get(handles.CheckboxTimelockAnalysis, 'Value') == 1
  213. set(handles.CheckboxTimelockGrpAvg, 'Value', 1);
  214. end
  215. % --- Executes on button press in CheckboxTimelockGrpAvg.
  216. function CheckboxTimelockGrpAvg_Callback(hObject, eventdata, handles)
  217. % --- Executes on button press in CheckboxFreqAnalysis.
  218. function CheckboxFreqAnalysis_Callback(hObject, eventdata, handles)
  219. if get(handles.CheckboxFreqAnalysis, 'Value') == 1
  220. set(handles.CheckboxFreqGrpAvg, 'Value', 1);
  221. end
  222. % --- Executes on button press in CheckboxFreqGrpAvg.
  223. function CheckboxFreqGrpAvg_Callback(hObject, eventdata, handles)
  224. %--- Checkboxes for source analysis stream: ---%
  225. %----------------------------------------------%
  226. % --- Executes on button press in CheckboxSegmentMRI.
  227. function CheckboxSegmentMRI_Callback(hObject, eventdata, handles)
  228. % --- Executes on button press in CheckboxHdmLeadfield.
  229. function CheckboxHdmLeadfield_Callback(hObject, eventdata, handles)
  230. % --- Executes on button press in CheckboxSourceFilter.
  231. function CheckboxSourceFilter_Callback(hObject, eventdata, handles)
  232. % --- Executes on button press in CheckboxSourceAnalysis.
  233. function CheckboxSourceAnalysis_Callback(hObject, eventdata, handles)
  234. % if get(handles.CheckboxSourceAnalysis, 'Value') == 1 %** Disabled for now
  235. % set(handles.CheckboxMakeSourceNifti, 'Value', 1); % Saves time
  236. % set(handles.CheckboxMakeSourceAfni, 'Value', 1);
  237. % else
  238. % set(handles.CheckboxMakeSourceNifti, 'Value', 0);
  239. % set(handles.CheckboxMakeSourceAfni, 'Value', 0);
  240. % end
  241. % --- Executes on button press in CheckboxMakeSourceNifti.
  242. function CheckboxMakeSourceNifti_Callback(hObject, eventdata, handles)
  243. % --- Executes on button press in CheckboxMakeSourceAfni.
  244. function CheckboxMakeSourceAfni_Callback(hObject, eventdata, handles)
  245. % --- Executes on button press in CheckboxNormaliseSource.
  246. function CheckboxNormaliseSource_Callback(hObject, eventdata, handles)
  247. if get(handles.CheckboxNormaliseSource, 'Value') == 1
  248. set(handles.CheckboxMakeNormSrcNifti, 'Value', 1);
  249. set(handles.CheckboxMakeNormSrcAfni, 'Value', 1);
  250. else
  251. set(handles.CheckboxMakeNormSrcNifti, 'Value', 0);
  252. set(handles.CheckboxMakeNormSrcAfni, 'Value', 0);
  253. end
  254. % --- Executes on button press in CheckboxMakeNormSrcNifti.
  255. function CheckboxMakeNormSrcNifti_Callback(hObject, eventdata, handles)
  256. % --- Executes on button press in CheckboxMakeNormSrcAfni.
  257. function CheckboxMakeNormSrcAfni_Callback(hObject, eventdata, handles)
  258. % --- Executes on button press in CheckboxGroupAvgNormSrc. ---%
  259. function CheckboxGroupAvgNormSrc_Callback(hObject, eventdata, handles)
  260. if get(handles.CheckboxGroupAvgNormSrc, 'Value') == 1
  261. set(handles.CheckboxMakeGrpAvgNifti, 'Value', 1);
  262. set(handles.CheckboxMakeGrpAvgAfni, 'Value', 1);
  263. else
  264. set(handles.CheckboxMakeGrpAvgNifti, 'Value', 0);
  265. set(handles.CheckboxMakeGrpAvgAfni, 'Value', 0);
  266. end
  267. % --- Executes on button press in CheckboxMakeGrpAvgNifti.
  268. function CheckboxMakeGrpAvgNifti_Callback(hObject, eventdata, handles)
  269. % --- Executes on button press in CheckboxMakeGrpAvgAfni.
  270. function CheckboxMakeGrpAvgAfni_Callback(hObject, eventdata, handles)
  271. %--- Executes on button press in CheckboxMakePLSmat. ---%
  272. %-------------------------------------------------------%
  273. function CheckboxMakePLSmat_Callback(hObject, eventdata, handles)
  274. if get(handles.CheckboxMakePLSmat, 'Value') == 0
  275. set(handles.CheckboxRunPLS, 'Value', 0);
  276. end
  277. % Update GUI panels (to enable/disable):
  278. handles = UpdatePLSmatInputData (handles);
  279. handles = UpdateTimeSettings (handles);
  280. handles = UpdateMaskSettings (handles);
  281. handles = UpdateBehaviorSettings (handles);
  282. handles = UpdatePLSrunSettings (handles);
  283. % Save handles:
  284. guidata(hObject, handles);
  285. %--- Executes on button press in CheckboxRunPLS. ---%
  286. %---------------------------------------------------%
  287. function CheckboxRunPLS_Callback(hObject, eventdata, handles)
  288. if get(handles.CheckboxRunPLS, 'Value') == 1
  289. set(handles.CheckboxMakePLSmat, 'Value', 1);
  290. end
  291. % Update GUI panels (to enable/disable):
  292. handles = UpdatePLSmatInputData (handles);
  293. handles = UpdateTimeSettings (handles);
  294. handles = UpdateMaskSettings (handles);
  295. handles = UpdateBehaviorSettings (handles);
  296. handles = UpdatePLSrunSettings (handles);
  297. % Save handles:
  298. guidata(hObject, handles);
  299. %======================================%
  300. % FUNCTIONS FOR OPENING VISUALIZATION: %
  301. %======================================%
  302. %--- Executes on button press in ButtonViewTimelockFreq. ---%
  303. %-----------------------------------------------------------%
  304. function ButtonViewTimelockFreq_Callback(hObject, eventdata, handles)
  305. VisualizeTimeFreq(handles.gui.BuilderMat);
  306. %--- Executes on button press in ButtonViewSources. ---%
  307. %------------------------------------------------------%
  308. function ButtonViewSources_Callback(hObject, eventdata, handles)
  309. VisualizeSourceData(handles.gui.BuilderMat);
  310. %--- Executes on button press in ButtonViewPLS. ---%
  311. %--------------------------------------------------%
  312. function ButtonViewPLS_Callback(hObject, eventdata, handles)
  313. ViewPLSresults
  314. %===================================%
  315. % FUNCTIONS FOR PLS INPUT SETTINGS: %
  316. %===================================%
  317. % --- Executes on selection change in ListboxPLSmatGroupID.
  318. function ListboxPLSmatGroupID_Callback(hObject, eventdata, handles)
  319. handles = UpdatePLSmatInputData(handles);
  320. guidata(hObject, handles);
  321. % --- Executes on selection change in ListboxPLSmatSubjID.
  322. function ListboxPLSmatSubjID_Callback(hObject, eventdata, handles)
  323. % --- Executes on selection change in ListboxPLSmatCondID.
  324. function ListboxPLSmatCondID_Callback(hObject, eventdata, handles)
  325. %--- Executes on button press in ButtonRmvPLSmatGroupID. ---%
  326. %--------------------------------------------------------%
  327. function ButtonRmvPLSmatGroupID_Callback(hObject, eventdata, handles)
  328. PLSmat = handles.PLSmat;
  329. if isempty(PLSmat.name.GroupID)
  330. return;
  331. end
  332. if length(PLSmat.name.GroupID) <= 1
  333. msgbox('Error: Cannot remove the last Group.', 'Error:')
  334. return;
  335. end
  336. % Exclude selected GroupID & data from PLSmat:
  337. SelectedIndex = get(handles.ListboxPLSmatGroupID, 'Value');
  338. PLSmat.name.GroupID (SelectedIndex) = [];
  339. PLSmat.name.SubjID (SelectedIndex) = [];
  340. PLSmat.paths.Afni4D (SelectedIndex) = [];
  341. PLSmat.paths.NormSource (SelectedIndex) = [];
  342. % Update GUI:
  343. handles.PLSmat = PLSmat;
  344. handles = UpdatePLSmatInputData(handles);
  345. % Save handles:
  346. guidata(hObject, handles);
  347. %--- Executes on button press in ButtonRmvPLSmatSubjID. ---%
  348. %----------------------------------------------------------%
  349. function ButtonRmvPLSmatSubjID_Callback(hObject, eventdata, handles)
  350. PLSmat = handles.PLSmat;
  351. if isempty(PLSmat.name.SubjID)
  352. return;
  353. end
  354. GroupIndex = get(handles.ListboxPLSmatGroupID, 'Value');
  355. if length(PLSmat.name.SubjID{GroupIndex}) <= 1
  356. msgbox('Error: Cannot remove the last Subject.', 'Error:');
  357. return;
  358. end
  359. % Exclude selected SubjID & data from PLSmat:
  360. SubjIndex = get(handles.ListboxPLSmatSubjID, 'Value');
  361. PLSmat.name.SubjID {GroupIndex}(SubjIndex) = [];
  362. PLSmat.paths.Afni4D {GroupIndex}(SubjIndex,:) = [];
  363. PLSmat.paths.NormSource {GroupIndex}(SubjIndex,:,:) = [];
  364. % Update GUI:
  365. handles.PLSmat = PLSmat;
  366. handles = UpdatePLSmatInputData(handles);
  367. % Save handles:
  368. guidata(hObject, handles);
  369. %--- Executes on button press in ButtonRmvPLSmatCondID. ---%
  370. %----------------------------------------------------------%
  371. function ButtonRmvPLSmatCondID_Callback(hObject, eventdata, handles)
  372. PLSmat = handles.PLSmat;
  373. if isempty(PLSmat.name.CondID)
  374. return;
  375. end
  376. if length(PLSmat.name.CondID) <= 1
  377. msgbox('Error: Cannot remove the last Condition.', 'Error:')
  378. return;
  379. end
  380. % Exclude selected CondID & data from PLSmat:
  381. SelectedIndex = get(handles.ListboxPLSmatCondID, 'Value');
  382. PLSmat.name.CondID(SelectedIndex) = [];
  383. for g = 1:length(PLSmat.name.GroupID)
  384. PLSmat.paths.Afni4D {g}(:,SelectedIndex) = [];
  385. PLSmat.paths.NormSource {g}(:,SelectedIndex,:) = [];
  386. end
  387. % Update GUI:
  388. handles.PLSmat = PLSmat;
  389. handles = UpdatePLSmatInputData(handles);
  390. % Save handles:
  391. guidata(hObject, handles);
  392. %--- Executes on button press in ButtonRestorePLSmatInput. ---%
  393. %-------------------------------------------------------------%
  394. function ButtonRestorePLSmatInput_Callback(hObject, eventdata, handles)
  395. PLSmat = handles.PLSmat;
  396. % Restore original Builder list of input data:
  397. PLSmat.name.GroupID = handles.name.GroupID;
  398. PLSmat.name.SubjID = handles.name.SubjID;
  399. PLSmat.name.CondID = handles.name.CondID;
  400. PLSmat.paths.Afni4D = handles.paths.Afni4DNormSource;
  401. PLSmat.paths.NormSource = handles.paths.NormSource;
  402. % Update GUI:
  403. handles.PLSmat = PLSmat;
  404. handles = UpdatePLSmatInputData(handles);
  405. % Save handles:
  406. guidata(hObject, handles);
  407. %--- Textbox for name ID of PLS session. ---%
  408. %-------------------------------------------%
  409. function TextboxPLSmatSessionID_Callback(hObject, eventdata, handles)
  410. InputID = deblank(get(handles.TextboxPLSmatSessionID, 'String'));
  411. InputID = regexprep(InputID, '\s+', '_');
  412. set(handles.TextboxPLSmatSessionID, 'String', InputID);
  413. handles = UpdatePLSmatInputData(handles);
  414. guidata(hObject, handles);
  415. %--- Update PLSmat input data & GUI panel: ---%
  416. %---------------------------------------------%
  417. function OutputHandles = UpdatePLSmatInputData(InputHandles)
  418. handles = InputHandles;
  419. PLSmat = handles.PLSmat;
  420. % Read GUI to update settings:
  421. PLSmat.SessionID = get(handles.TextboxPLSmatSessionID, 'String');
  422. % Update GroupID listbox:
  423. set(handles.ListboxPLSmatGroupID, 'String', PLSmat.name.GroupID);
  424. GroupIndex = get(handles.ListboxPLSmatGroupID, 'Value');
  425. MaxGroupIndex = length(PLSmat.name.GroupID);
  426. if isempty(GroupIndex) || GroupIndex == 0 || GroupIndex > MaxGroupIndex
  427. set(handles.ListboxPLSmatGroupID, 'Value', MaxGroupIndex);
  428. GroupIndex = MaxGroupIndex;
  429. end
  430. % Update SubjID listbox:
  431. if isempty(PLSmat.name.SubjID)
  432. set(handles.ListboxPLSmatSubjID, 'String', []);
  433. MaxSubjIndex = 0;
  434. else
  435. set(handles.ListboxPLSmatSubjID, 'String', PLSmat.name.SubjID{GroupIndex});
  436. MaxSubjIndex = length(PLSmat.name.SubjID{GroupIndex});
  437. end
  438. SubjIndex = get(handles.ListboxPLSmatSubjID, 'Value');
  439. if isempty(SubjIndex) || SubjIndex == 0 || SubjIndex > MaxSubjIndex
  440. set(handles.ListboxPLSmatSubjID, 'Value', MaxSubjIndex);
  441. end
  442. % Update CondID listbox:
  443. set(handles.ListboxPLSmatCondID, 'String', PLSmat.name.CondID);
  444. CondIndex = get(handles.ListboxPLSmatCondID, 'Value');
  445. MaxCondIndex = length(PLSmat.name.CondID);
  446. if isempty(CondIndex) || CondIndex == 0 || CondIndex > MaxCondIndex
  447. set(handles.ListboxPLSmatCondID, 'Value', MaxCondIndex);
  448. end
  449. % Enable/Disable GUI components:
  450. if get(handles.CheckboxMakePLSmat, 'Value') == 1
  451. set(findall(handles.PanelPLSmatInput, '-property', 'Enable'), 'Enable', 'on');
  452. else
  453. set(findall(handles.PanelPLSmatInput, '-property', 'Enable'), 'Enable', 'off');
  454. set(handles.ListboxPLSmatGroupID, 'Enable', 'on');
  455. set(handles.ListboxPLSmatSubjID, 'Enable', 'on');
  456. set(handles.ListboxPLSmatCondID, 'Enable', 'on');
  457. set(handles.TextHeaderPLSmatGroupIDs, 'Enable', 'on');
  458. set(handles.TextHeaderPLSmatSubjIDs, 'Enable', 'on');
  459. set(handles.TextHeaderPLSmatCondIDs, 'Enable', 'on');
  460. end
  461. % Set output handles:
  462. handles.PLSmat = PLSmat;
  463. OutputHandles = handles;
  464. %--- Reset PLSmat input data & GUI panel: ---%
  465. %--------------------------------------------%
  466. function OutputHandles = ResetPLSmatInputData(InputHandles)
  467. handles = InputHandles;
  468. PLSmat = handles.PLSmat;
  469. % Reset PLSmat input settings:
  470. PLSmat.name.GroupID = [];
  471. PLSmat.name.SubjID = [];
  472. PLSmat.name.CondID = [];
  473. PLSmat.paths.Afni4D = [];
  474. PLSmat.paths.NormSource = [];
  475. PLSmat.SessionID = [];
  476. % Reset GUI panel:
  477. set(handles.ListboxPLSmatGroupID, 'String', []);
  478. set(handles.ListboxPLSmatGroupID, 'Value', 1);
  479. set(handles.ListboxPLSmatSubjID, 'String', []);
  480. set(handles.ListboxPLSmatSubjID, 'Value', 1);
  481. set(handles.ListboxPLSmatCondID, 'String', []);
  482. set(handles.ListboxPLSmatCondID, 'Value', 1);
  483. set(handles.TextboxPLSmatSessionID, 'String', []);
  484. % Set output handles:
  485. handles.PLSmat = PLSmat;
  486. OutputHandles = handles;
  487. %======================================%
  488. % FUNCTIONS FOR PLS MAT TIME SETTINGS: %
  489. %======================================%
  490. %--- Executes on slider movement for PLS start time. ---%
  491. %-------------------------------------------------------%
  492. function SliderTimeStartPLS_Callback(hObject, eventdata, handles)
  493. if isempty(handles.gui.BuilderMat)
  494. msgbox('Warning: Load Builder .mat first.', 'Warning:');
  495. return;
  496. end
  497. StartIndex = round(get(handles.SliderTimeStartPLS, 'Value'));
  498. EndIndex = round(get(handles.SliderTimeEndPLS, 'Value'));
  499. if StartIndex > EndIndex
  500. StartIndex = EndIndex;
  501. end
  502. set(handles.SliderTimeStartPLS, 'Value', StartIndex);
  503. set(handles.TextboxTimeStartPLS, 'String', handles.time.str.Windows{StartIndex,1});
  504. handles = UpdateTimeSettings(handles);
  505. guidata(hObject, handles);
  506. %--- Executes on slider movement for PLS end time. ---%
  507. %-----------------------------------------------------%
  508. function SliderTimeEndPLS_Callback(hObject, eventdata, handles)
  509. if isempty(handles.gui.BuilderMat)
  510. return;
  511. end
  512. EndIndex = round(get(handles.SliderTimeEndPLS, 'Value'));
  513. StartIndex = round(get(handles.SliderTimeStartPLS, 'Value'));
  514. if EndIndex < StartIndex
  515. EndIndex = StartIndex;
  516. end
  517. set(handles.SliderTimeEndPLS, 'Value', EndIndex);
  518. set(handles.TextboxTimeEndPLS, 'String', handles.time.str.Windows{EndIndex,2});
  519. handles = UpdateTimeSettings(handles);
  520. guidata(hObject, handles);
  521. %--- Textbox to display or enter PLS start time: ---%
  522. %---------------------------------------------------%
  523. function TextboxTimeStartPLS_Callback(hObject, eventdata, handles)
  524. if isempty(handles.gui.BuilderMat)
  525. return;
  526. end
  527. % Check input start time:
  528. InputStartTime = str2num(get(handles.TextboxTimeStartPLS, 'String'));
  529. InputEndTime = str2num(get(handles.TextboxTimeEndPLS, 'String'));
  530. if isempty(InputStartTime) || InputStartTime > InputEndTime
  531. StartIndex = get(handles.SliderTimeStartPLS, 'Value');
  532. set(handles.TextboxTimeStartPLS, 'String', handles.time.str.Windows{StartIndex,1});
  533. end
  534. % Find closest time-index:
  535. [~, ClosestIndex] = min(abs(InputStartTime - handles.time.Windows(:,1)));
  536. StartIndex = ClosestIndex;
  537. if StartIndex > EndIndex;
  538. StartIndex = EndIndex;
  539. end
  540. set(handles.SliderTimeStartPLS, 'Value', StartIndex);
  541. set(handles.TextboxTimeStartPLS, 'String', handles.time.str.Windows{StartIndex,1});
  542. % Save handles:
  543. handles = UpdateTimeSettings(handles);
  544. guidata(hObject, handles);
  545. %--- Textbox to display or enter PLS end time: ---%
  546. %-------------------------------------------------%
  547. function TextboxTimeEndPLS_Callback(hObject, eventdata, handles)
  548. if isempty(handles.gui.BuilderMat)
  549. return;
  550. end
  551. % Check input end time:
  552. InputStartTime = str2num(get(handles.TextboxTimeStartPLS, 'String'));
  553. InputEndTime = str2num(get(handles.TextboxTimeEndPLS, 'String'));
  554. if isempty(InputEndTime) || InputEndTime < InputStartTime
  555. EndIndex = get(handles.SliderTimeEndPLS, 'Value');
  556. set(handles.TextboxTimeEndPLS, 'String', handles.time.str.Windows{EndIndex,2});
  557. end
  558. % Find closest time-index:
  559. [~, ClosestIndex] = min(abs(EndTime - handles.time.Windows(:,2)));
  560. EndIndex = ClosestIndex;
  561. if EndIndex < StartIndex
  562. EndIndex = StartIndex;
  563. end
  564. set(handles.SliderTimeEndPLS, 'Value', EndIndex);
  565. set(handles.TextboxTimeEndPLS, 'String', handles.time.str.Windows{EndIndex,2});
  566. % Save handles:
  567. handles = UpdateTimeSettings(handles);
  568. guidata(hObject, handles);
  569. %--- Executes on button press in CheckboxManualTimeSelect. ---%
  570. %---------------------------------------------------------------%
  571. function CheckboxManualTimeSelect_Callback(hObject, eventdata, handles)
  572. handles = UpdateTimeSettings(handles);
  573. guidata(hObject, handles);
  574. % --- Executes on selection change in ListboxManualTimeSelect.
  575. function ListboxManualTimeSelect_Callback(hObject, eventdata, handles)
  576. %--- Executes on button press in ButtonManualTimeSelect. ---%
  577. %--------------------------------------------------------------%
  578. function ButtonManualTimeSelect_Callback(hObject, eventdata, handles)
  579. if isempty(handles.gui.BuilderMat)
  580. return;
  581. end
  582. SelectedIndices = listdlg('PromptString', 'Select time-indices for PLS analysis:',...
  583. 'ListSize', [300, 300], 'SelectionMode', 'multiple',...
  584. 'ListString', handles.time.str.Windows(:,3));
  585. if isempty(SelectedIndices)
  586. return; % If user cancels
  587. end
  588. SelectedIndices = sort(SelectedIndices);
  589. handles.gui.ManualTimeIndices = SelectedIndices; % Keep in memory for switch-back
  590. handles = UpdateTimeSettings(handles);
  591. guidata(hObject, handles);
  592. %--- Updates time settings & GUI panel: ---%
  593. %------------------------------------------%
  594. function OutputHandles = UpdateTimeSettings(InputHandles)
  595. handles = InputHandles;
  596. % Read GUI to update PLSmat:
  597. if get(handles.CheckboxManualTimeSelect, 'Value') == 0
  598. StartTimeIndex = round(get(handles.SliderTimeStartPLS, 'Value'));
  599. EndTimeIndex = round(get(handles.SliderTimeEndPLS, 'Value'));
  600. handles.PLSmat.TimeIndices = [StartTimeIndex:EndTimeIndex];
  601. handles.PLSmat.ManualTimeSelect = 'no';
  602. else
  603. handles.PLSmat.TimeIndices = handles.gui.ManualTimeIndices;
  604. handles.PLSmat.ManualTimeSelect = 'yes';
  605. end
  606. % Update listbox:
  607. if isempty(handles.gui.ManualTimeIndices)
  608. set(handles.ListboxManualTimeSelect, 'String', []);
  609. else
  610. set(handles.ListboxManualTimeSelect, 'String',...
  611. handles.time.str.Windows(handles.gui.ManualTimeIndices, 3));
  612. end
  613. SelectedIndex = get(handles.ListboxManualTimeSelect, 'Value');
  614. MaxListIndex = length(handles.gui.ManualTimeIndices);
  615. if isempty(SelectedIndex) || SelectedIndex == 0 || SelectedIndex > MaxListIndex
  616. set(handles.ListboxManualTimeSelect, 'Value', MaxListIndex);
  617. end
  618. % Enable/Disable GUI time components:
  619. if get(handles.CheckboxMakePLSmat, 'Value') == 1
  620. set(findall(handles.PanelPLSTimeSettings, '-property', 'Enable'), 'Enable', 'on');
  621. else
  622. set(findall(handles.PanelPLSTimeSettings, '-property', 'Enable'), 'Enable', 'off');
  623. end
  624. if size(handles.time.Windows, 1) == 1
  625. set(handles.SliderTimeStartPLS, 'Enable', 'off');
  626. set(handles.SliderTimeEndPLS, 'Enable', 'off');
  627. set(handles.TextboxTimeStartPLS, 'Enable', 'off');
  628. set(handles.TextboxTimeEndPLS, 'Enable', 'off');
  629. set(handles.TextTimeStartHeaderPLS, 'Enable', 'off');
  630. set(handles.TextTimeEndHeaderPLS, 'Enable', 'off');
  631. end
  632. if get(handles.CheckboxManualTimeSelect, 'Value') == 0
  633. set(handles.ButtonManualTimeSelect, 'Enable', 'off');
  634. set(handles.ListboxManualTimeSelect, 'Enable', 'off');
  635. else
  636. set(handles.SliderTimeStartPLS, 'Enable', 'off');
  637. set(handles.SliderTimeEndPLS, 'Enable', 'off');
  638. set(handles.TextboxTimeStartPLS, 'Enable', 'off');
  639. set(handles.TextboxTimeEndPLS, 'Enable', 'off');
  640. set(handles.TextTimeStartHeaderPLS, 'Enable', 'off');
  641. set(handles.TextTimeEndHeaderPLS, 'Enable', 'off');
  642. end
  643. % Set output handles:
  644. OutputHandles = handles;
  645. %--- Reset time settings & GUI panel: ---%
  646. %----------------------------------------%
  647. function OutputHandles = ResetTimeSettings(InputHandles)
  648. handles = InputHandles;
  649. % Reset PLSmat time settings:
  650. handles.PLSmat.TimeIndices = [1:size(handles.time.Windows, 1)];
  651. handles.PLSmat.ManualTimeSelect = 'no';
  652. handles.gui.ManualTimeIndices = [];
  653. % Reset GUI time panel back to default:
  654. SliderStep = 1 / size(handles.time.Windows, 1);
  655. set(handles.CheckboxManualTimeSelect, 'Value', 0);
  656. set(handles.ListboxManualTimeSelect, 'String', []);
  657. set(handles.SliderTimeStartPLS, 'Min', 1);
  658. set(handles.SliderTimeStartPLS, 'Max', size(handles.time.Windows, 1));
  659. set(handles.SliderTimeStartPLS, 'SliderStep', [SliderStep SliderStep]);
  660. set(handles.SliderTimeStartPLS, 'Value', 1);
  661. set(handles.SliderTimeEndPLS, 'Min', 1);
  662. set(handles.SliderTimeEndPLS, 'Max', size(handles.time.Windows, 1));
  663. set(handles.SliderTimeEndPLS, 'SliderStep', [SliderStep SliderStep]);
  664. set(handles.SliderTimeEndPLS, 'Value', size(handles.time.Windows, 1));
  665. set(handles.TextboxTimeStartPLS, 'String', handles.time.str.Windows{1,1});
  666. set(handles.TextboxTimeEndPLS, 'String', handles.time.str.Windows{end,2});
  667. % Set output handles:
  668. OutputHandles = handles;
  669. %======================================%
  670. % FUNCTIONS FOR PLS MAT MASK SETTINGS: %
  671. %======================================%
  672. %--- Executes on button-group in PanelPLSMaskSettings. ---%
  673. %---------------------------------------------------------%
  674. function PanelPLSMaskSettings_SelectionChangeFcn(hObject, eventdata, handles)
  675. handles = UpdateMaskSettings(handles);
  676. guidata(hObject, handles);
  677. %--- Executes on button press in CheckboxDataSpecificMask. ---%
  678. %-------------------------------------------------------------%
  679. function CheckboxDataSpecificMask_Callback(hObject, eventdata, handles)
  680. handles = UpdateMaskSettings(handles);
  681. guidata(hObject, handles);
  682. %--- User enters % threshold to keep voxels for data-specific mask: ---%
  683. %----------------------------------------------------------------------%
  684. function TextboxKeepVoxelThresh_Callback(hObject, eventdata, handles)
  685. if isempty(get(handles.TextboxKeepVoxelThresh, 'String'))
  686. msgbox('Error: Voxel inclusion threshold not specified. Default set to 90%.');
  687. set(handles.TextboxROISize, 'String', num2str(1));
  688. end
  689. handles = UpdateMaskSettings(handles);
  690. guidata(hObject, handles);
  691. %--- Executes on button press in ButtonSelectBrainMask. ---%
  692. %----------------------------------------------------------%
  693. function ButtonSelectBrainMask_Callback(hObject, eventdata, handles)
  694. % Get initial search path:
  695. if ~isempty(handles.PLSmat.BrainMaskFile)
  696. [SearchPath, ~, ~] = fileparts(handles.gui.DefaultBrainMask);
  697. else
  698. [SearchPath, ~, ~] = fileparts(handles.PLSmat.BrainMaskFile);
  699. end
  700. % Select brain mask:
  701. [MaskFile, MaskPath] = uigetfile([SearchPath,'/*+tlrc.BRIK'],...
  702. 'Select Mask File:', 'MultiSelect', 'off');
  703. if MaskFile == 0
  704. return; % If user cancels
  705. end
  706. handles.PLSmat.BrainMaskFile = [MaskPath,MaskFile];
  707. set(handles.TextboxBrainMaskFile, 'String', handles.PLSmat.BrainMaskFile);
  708. % Save handles:
  709. handles = UpdateMaskSettings(handles);
  710. guidata(hObject, handles);
  711. %--- Textbox to display selected brain mask. ---%
  712. %-----------------------------------------------%
  713. function TextboxBrainMaskFile_Callback(hObject, eventdata, handles)
  714. EnteredText = get(handles.TextboxBrainMaskFile, 'String');
  715. if ~isequal(EnteredText, handles.PLSmat.BrainMaskFile)
  716. set(handles.TextboxBrainMaskFile, 'String', handles.PLSmat.BrainMaskFile);
  717. msgbox('Note: Use the button to change brain mask file.', 'Note:');
  718. end
  719. %--- Executes on button press in ButtonSelectROIMask. ---%
  720. %--------------------------------------------------------%
  721. function ButtonSelectROIMask_Callback(hObject, eventdata, handles)
  722. % Get initial search path:
  723. if ~isempty(handles.PLSmat.ROIMaskFile)
  724. [SearchPath, ~, ~] = fileparts(handles.gui.DefaultROIMask);
  725. else
  726. [SearchPath, ~, ~] = fileparts(handles.PLSmat.ROIMaskFile);
  727. end
  728. % Select ROI mask:
  729. [MaskFile, MaskPath] = uigetfile([SearchPath,'/*.xls'],...
  730. 'Select Mask File:', 'MultiSelect', 'off');
  731. if MaskFile == 0
  732. return; % If user cancels
  733. end
  734. handles.PLSmat.ROIMaskFile = [MaskPath,MaskFile];
  735. set(handles.TextboxROIMaskFile, 'String', handles.PLSmat.ROIMaskFile);
  736. % Save handles:
  737. handles = UpdateMaskSettings(handles);
  738. guidata(hObject, handles);
  739. %--- Textbox to display selected ROI mask. ---%
  740. %---------------------------------------------%
  741. function TextboxROIMaskFile_Callback(hObject, eventdata, handles)
  742. EnteredText = get(handles.TextboxROIMaskFile, 'String');
  743. if ~isequal(EnteredText, handles.PLSmat.ROIMaskFile)
  744. set(handles.TextboxROIMaskFile, 'String', handles.PLSmat.ROIMaskFile);
  745. msgbox('Note: Use the button to change ROI mask file.', 'Note:');
  746. end
  747. %--- Textbox to specify ROI voxel size: ---%
  748. %------------------------------------------%
  749. function TextboxROISize_Callback(hObject, eventdata, handles)
  750. if isempty(get(handles.TextboxROISize, 'String'))
  751. msgbox('Error: ROI size for ROI mask not specified. Default set to 1.');
  752. set(handles.TextboxROISize, 'String', num2str(1));
  753. end
  754. if str2num(get(handles.TextboxROISize, 'String')) == 0
  755. msgbox('Error: ROI size for ROI mask cannot be 0. Default set to 1.');
  756. set(handles.TextboxROISize, 'String', num2str(1));
  757. end
  758. handles = UpdateMaskSettings(handles);
  759. guidata(hObject, handles);
  760. %--- Updates mask settings & GUI panel: ---%
  761. %------------------------------------------%
  762. function OutputHandles = UpdateMaskSettings(InputHandles)
  763. handles = InputHandles;
  764. % Read GUI to update PLSmat:
  765. if get(handles.ButtonBrainMask, 'Value') == 1
  766. handles.PLSmat.MaskType = 'BrainMask';
  767. elseif get(handles.ButtonROIMask, 'Value') == 1
  768. handles.PLSmat.MaskType = 'ROIMask';
  769. end
  770. if get(handles.CheckboxDataSpecificMask, 'Value') == 1
  771. handles.PLSmat.DataSpecificMask = 'yes';
  772. else
  773. handles.PLSmat.DataSpecificMask = 'no';
  774. end
  775. handles.PLSmat.MaskKeepVoxThresh = ...
  776. str2num(get(handles.TextboxKeepVoxelThresh, 'String')) / 100;
  777. ROISize = round(str2num(get(handles.TextboxROISize, 'String')));
  778. handles.PLSmat.ROIBlobSize = [-ROISize:ROISize];
  779. % Enable/Disable GUI mask components:
  780. if get(handles.CheckboxMakePLSmat, 'Value') == 1
  781. set(findall(handles.PanelPLSMaskSettings, '-property', 'Enable'), 'Enable', 'on');
  782. %set(handles.TextboxBrainMaskFile, 'Enable', 'inactive');
  783. %set(handles.TextboxROIMaskFile, 'Enable', 'inactive');
  784. else
  785. set(findall(handles.PanelPLSMaskSettings, '-property', 'Enable'), 'Enable', 'off');
  786. end
  787. if get(handles.ButtonBrainMask, 'Value') == 1
  788. if get(handles.CheckboxDataSpecificMask, 'Value') == 1
  789. set(handles.ButtonSelectBrainMask, 'Enable', 'off');
  790. set(handles.TextboxBrainMaskFile, 'Enable', 'off');
  791. else
  792. set(handles.TextboxKeepVoxelThresh, 'Enable', 'off');
  793. set(handles.TextKeepVoxelThresh, 'Enable', 'off');
  794. end
  795. set(handles.ButtonSelectROIMask, 'Enable', 'off');
  796. set(handles.TextboxROIMaskFile, 'Enable', 'off');
  797. set(handles.TextboxROISize, 'Enable', 'off');
  798. set(handles.TextROISize, 'Enable', 'off');
  799. elseif get(handles.ButtonROIMask, 'Value') == 1
  800. set(handles.CheckboxDataSpecificMask, 'Enable', 'off');
  801. set(handles.ButtonSelectBrainMask, 'Enable', 'off');
  802. set(handles.TextboxBrainMaskFile, 'Enable', 'off');
  803. set(handles.TextboxKeepVoxelThresh, 'Enable', 'off');
  804. set(handles.TextKeepVoxelThresh, 'Enable', 'off');
  805. end
  806. % Set output handles:
  807. OutputHandles = handles;
  808. %--- Reset mask settings & GUI panel: ---%
  809. %----------------------------------------%
  810. function OutputHandles = ResetMaskSettings(InputHandles)
  811. handles = InputHandles;
  812. % Reset PLSmat mask settings:
  813. handles.PLSmat.MaskType = 'BrainMask';
  814. handles.PLSmat.DataSpecificMask = 'yes';
  815. handles.PLSmat.MaskKeepVoxThresh = 0.90;
  816. handles.PLSmat.BrainMaskFile = handles.gui.DefaultBrainMask;
  817. handles.PLSmat.ROIMaskFile = handles.gui.DefaultROIMask;
  818. handles.PLSmat.ROIBlobSize = [-1:1];
  819. % Reset GUI mask panel back to default:
  820. set(handles.ButtonBrainMask, 'Value', 1);
  821. set(handles.ButtonROIMask, 'Value', 0);
  822. set(handles.TextboxROISize, 'String', num2str(1));
  823. set(handles.TextboxBrainMaskFile, 'String', handles.gui.DefaultBrainMask);
  824. set(handles.TextboxROIMaskFile, 'String', handles.gui.DefaultROIMask);
  825. set(handles.CheckboxDataSpecificMask, 'Value', 1);
  826. set(handles.TextboxKeepVoxelThresh, 'String', '90');
  827. % Set output handles:
  828. OutputHandles = handles;
  829. %====================================%
  830. % FUNCTIONS FOR BEHAVIOR & SEED PLS: %
  831. %====================================%
  832. %--- Textbox for name ID of behavior files loaded. ---%
  833. %-----------------------------------------------------%
  834. function TextboxBhvSeedID_Callback(hObject, eventdata, handles)
  835. InputID = deblank(get(handles.TextboxBhvSeedID, 'String'));
  836. InputID = regexprep(InputID, '\s+', '_');
  837. set(handles.TextboxBhvSeedID, 'String', InputID);
  838. handles = UpdateBehaviorSettings(handles);
  839. guidata(hObject, handles);
  840. %--- Executes on button press in ButtonLoadBhvFile. ---%
  841. %------------------------------------------------------%
  842. function ButtonLoadBhvFile_Callback(hObject, eventdata, handles)
  843. if ~isempty(handles.PLSmat.BhvFile)
  844. [SearchPath, ~, ~] = fileparts(handles.PLSmat.BhvFile);
  845. SearchPath = [SearchPath,'/'];
  846. else
  847. SearchPath = [];
  848. end
  849. [BhvFile, BhvPath] = uigetfile([SearchPath,'*.xls'],...
  850. 'Select Behavior file:', 'MultiSelect', 'off');
  851. if BhvFile == 0
  852. return; % If user cancels
  853. end
  854. handles.PLSmat.BhvFile = [BhvPath,BhvFile];
  855. set(handles.TextboxBhvFile, 'String', handles.PLSmat.BhvFile);
  856. handles = UpdateBehaviorSettings(handles);
  857. guidata(hObject, handles);
  858. %--- Executes on button press in ButtonClearBhvFile. ---%
  859. %-------------------------------------------------------%
  860. function ButtonClearBhvFile_Callback(hObject, eventdata, handles)
  861. handles.PLSmat.BhvFile = [];
  862. set(handles.TextboxBhvFile, 'String', []);
  863. handles = UpdateBehaviorSettings(handles);
  864. guidata(hObject, handles);
  865. %--- Textbox to display selected behavior .xls. ---%
  866. %--------------------------------------------------%
  867. function TextboxBhvFile_Callback(hObject, eventdata, handles)
  868. EnteredText = get(handles.TextboxBhvFile, 'String');
  869. if ~isequal(EnteredText, handles.PLSmat.BhvFile)
  870. set(handles.TextboxBhvFile, 'String', handles.PLSmat.BhvFile);
  871. msgbox('Note: Use button to change bhv .xls file.', 'Note:');
  872. end
  873. %--- Executes on button press in ButtonLoadSeedFile. ---%
  874. %-------------------------------------------------------%
  875. function ButtonLoadSeedFile_Callback(hObject, eventdata, handles)
  876. if ~isempty(handles.PLSmat.SeedFile)
  877. [SearchPath, ~, ~] = fileparts(handles.PLSmat.SeedFile);
  878. SearchPath = [SearchPath,'/'];
  879. else
  880. SearchPath = [];
  881. end
  882. [SeedFile, SeedPath] = uigetfile([SearchPath,'*.xls'],...
  883. 'Select Seed file:', 'MultiSelect', 'off');
  884. if SeedFile == 0
  885. return; % If user cancels
  886. end
  887. handles.PLSmat.SeedFile = [SeedPath,SeedFile];
  888. set(handles.TextboxSeedFile, 'String', handles.PLSmat.SeedFile);
  889. handles = UpdateBehaviorSettings(handles);
  890. guidata(hObject, handles);
  891. %--- Executes on button press in ButtonClearSeedFile. ---%
  892. %--------------------------------------------------------%
  893. function ButtonClearSeedFile_Callback(hObject, eventdata, handles)
  894. handles.PLSmat.SeedFile = [];
  895. set(handles.TextboxSeedFile, 'String', []);
  896. handles = UpdateBehaviorSettings(handles);
  897. guidata(hObject, handles);
  898. %--- Textbox to display selected seed .xls. ---%
  899. %----------------------------------------------%
  900. function TextboxSeedFile_Callback(hObject, eventdata, handles)
  901. EnteredText = get(handles.TextboxSeedFile, 'String');
  902. if ~isequal(EnteredText, handles.PLSmat.SeedFile)
  903. set(handles.TextboxSeedFile, 'String', handles.PLSmat.SeedFile);
  904. msgbox('Note: Use button to change seed .xls file.');
  905. end
  906. %--- Textbox to specify seed size. ---%
  907. %-------------------------------------%
  908. function TextboxSeedSize_Callback(hObject, eventdata, handles)
  909. if isempty(get(handles.TextboxSeedSize, 'String'))
  910. msgbox('Error: Seed size for seeds not specified. Default set to 1.', 'Error:')
  911. set(handles.TextboxSeedSize, 'String', num2str(1));
  912. end
  913. if str2num(get(handles.TextboxSeedSize, 'String')) == 0
  914. msgbox('Error: Seed size for seeds cannot be 0. Default set to 1.', 'Error:')
  915. set(handles.TextboxSeedSize, 'String', num2str(1));
  916. end
  917. handles = UpdateBehaviorSettings(handles);
  918. guidata(hObject, handles);
  919. %--- Updates behavior settings & GUI panel. ---%
  920. %----------------------------------------------%
  921. function OutputHandles = UpdateBehaviorSettings(InputHandles)
  922. handles = InputHandles;
  923. % Read GUI to update PLSmat:
  924. handles.PLSmat.BhvSeedID = get(handles.TextboxBhvSeedID, 'String');
  925. SeedSize = round(str2num(get(handles.TextboxSeedSize, 'String')));
  926. handles.PLSmat.SeedBlobSize = [-SeedSize:SeedSize];
  927. % Enable/disable GUI behavior components:
  928. if get(handles.CheckboxMakePLSmat, 'Value') == 1
  929. set(findall(handles.PanelPLSBhvSeedSettings, '-property', 'Enable'), 'Enable', 'on');
  930. %set(handles.TextboxBhvFile, 'Enable', 'inactive');
  931. %set(handles.TextboxSeedFile, 'Enable', 'inactive');
  932. else
  933. set(findall(handles.PanelPLSBhvSeedSettings, '-property', 'Enable'), 'Enable', 'off');
  934. end
  935. if isempty(handles.PLSmat.SeedFile)
  936. set(handles.TextboxSeedSize, 'Enable', 'off');
  937. set(handles.TextSeedSize, 'Enable', 'off');
  938. end
  939. % Set output handles:
  940. OutputHandles = handles;
  941. %--- Reset behavior settings & GUI panel. ---%
  942. %--------------------------------------------%
  943. function OutputHandles = ResetBehaviorSettings(InputHandles)
  944. handles = InputHandles;
  945. % Reset PLSmat behavior settings:
  946. handles.PLSmat.BhvSeedID = [];
  947. handles.PLSmat.BhvFile = [];
  948. handles.PLSmat.SeedFile = [];
  949. handles.PLSmat.SeedBlobSize = [-1:1];
  950. % Reset GUI behavior panel back to default:
  951. set(handles.TextboxBhvSeedID, 'String', []);
  952. set(handles.TextboxBhvFile, 'String', []);
  953. set(handles.TextboxSeedFile, 'String', []);
  954. set(handles.TextboxSeedSize, 'String', num2str(1));
  955. % Set output handles:
  956. OutputHandles = handles;
  957. %=====================================%
  958. % GUI FUNCTIONS FOR PLS RUN SETTINGS: %
  959. %=====================================%
  960. %--- Executes on button press in ButtonPLSReadme. ---%
  961. %----------------------------------------------------%
  962. function ButtonPLSReadme_Callback(hObject, eventdata, handles)
  963. [PipelineDir, ~, ~] = fileparts(which('DriverGUI.m'));
  964. open([PipelineDir,'/MEGPLS_TOOLBOX/PLS_Tools/pls_nk_functions/PLS_README.txt']);
  965. %--- Executes on selection change in DropdownPLSMethod. ---%
  966. %----------------------------------------------------------%
  967. function DropdownPLSMethod_Callback(hObject, eventdata, handles)
  968. handles = UpdatePLSrunSettings(handles);
  969. guidata(hObject, handles);
  970. %--- Executes on button press in CheckboxSplitHalfPLS. ---%
  971. %---------------------------------------------------------%
  972. function CheckboxSplitHalfPLS_Callback(hObject, eventdata, handles)
  973. if get(handles.CheckboxSplitHalfPLS, 'Value') == 1
  974. set(handles.TextboxNumSplits, 'String', num2str(100));
  975. set(handles.TextboxNumPermutations, 'String', num2str(100));
  976. set(handles.TextboxNumBootstraps, 'String', num2str(200));
  977. else
  978. set(handles.TextboxNumSplits, 'String', num2str(0));
  979. set(handles.TextboxNumPermutations, 'String', num2str(500));
  980. set(handles.TextboxNumBootstraps, 'String', num2str(500));
  981. end
  982. handles = UpdatePLSrunSettings(handles);
  983. guidata(hObject, handles);
  984. %--- Textbox to specify number of PLS splits. ---%
  985. %------------------------------------------------%
  986. function TextboxNumSplits_Callback(hObject, eventdata, handles)
  987. if get(handles.CheckboxSplitHalfPLS, 'Value') == 1
  988. if isempty(get(handles.TextboxNumSplits, 'String'))
  989. msgbox('Note: Number of splits not specified. Default set to 100.')
  990. set(handles.TextboxNumSplits, 'String', num2str(100));
  991. end
  992. if str2num(get(handles.TextboxNumSplits, 'String')) > 100
  993. msgbox('Warning: For Splithalf-PLS, recommend # splits to be < 100.')
  994. end
  995. elseif get(handles.CheckboxSplitHalfPLS, 'Value') == 0
  996. set(handles.TextboxNumSplits, 'String', num2str(0));
  997. end
  998. handles = UpdatePLSrunSettings(handles);
  999. guidata(hObject, handles);
  1000. %--- Textbox to specify number of PLS permutations. ---%
  1001. %------------------------------------------------------%
  1002. function TextboxNumPermutations_Callback(hObject, eventdata, handles)
  1003. if get(handles.CheckboxSplitHalfPLS, 'Value') == 1
  1004. if isempty(get(handles.TextboxNumPermutations, 'String'))
  1005. msgbox('Note: Number of permutations not specified. Default set to 100.')
  1006. set(handles.TextboxNumPermutations, 'String', num2str(100));
  1007. end
  1008. if str2num(get(handles.TextboxNumPermutations, 'String')) > 100
  1009. msgbox('Warning: For Splithalf-PLS, recommend # perm. to be < 100.')
  1010. end
  1011. elseif get(handles.CheckboxSplitHalfPLS, 'Value') == 0
  1012. if isempty(get(handles.TextboxNumPermutations, 'String'))
  1013. msgbox('Note: Number of permutations not specified. Default set to 500.')
  1014. set(handles.TextboxNumPermutations, 'String', num2str(500));
  1015. end
  1016. end
  1017. handles = UpdatePLSrunSettings(handles);
  1018. guidata(hObject, handles);
  1019. %--- Textbox to specify number of PLS bootstraps. ---%
  1020. %------------------------------------------------------%
  1021. function TextboxNumBootstraps_Callback(hObject, eventdata, handles)
  1022. if get(handles.CheckboxSplitHalfPLS, 'Value') == 1
  1023. if isempty(get(handles.TextboxNumBootstraps, 'String'))
  1024. msgbox('Note: Number of bootstraps not specified. Default set to 200.')
  1025. set(handles.TextboxNumBootstraps, 'String', num2str(200));
  1026. end
  1027. if str2num(get(handles.TextboxNumBootstraps, 'String')) > 200
  1028. msgbox('Warning: For Splithalf-PLS, recommend # perm. to be < 200.')
  1029. end
  1030. elseif get(handles.CheckboxSplitHalfPLS, 'Value') == 0
  1031. if isempty(get(handles.TextboxNumBootstraps, 'String'))
  1032. msgbox('Note: Number of bootstraps not specified. Default set to 500.')
  1033. set(handles.TextboxNumBootstraps, 'String', num2str(500));
  1034. end
  1035. end
  1036. handles = UpdatePLSrunSettings(handles);
  1037. guidata(hObject, handles);
  1038. %--- Textbox to enter PLS non-rotated contrast. ---%
  1039. %--------------------------------------------------%
  1040. function TextboxNRContrast_Callback(hObject, eventdata, handles)
  1041. handles = UpdatePLSrunSettings(handles);
  1042. guidata(hObject, handles);
  1043. %--- Textbox for name ID of PLS non-rotated contrast. ---%
  1044. %--------------------------------------------------------%
  1045. function TextboxNRContrastID_Callback(hObject, eventdata, handles)
  1046. InputID = deblank(get(handles.TextboxNRContrastID, 'String'));
  1047. InputID = regexprep(InputID, '\s+', '_');
  1048. set(handles.TextboxNRContrastID, 'String', InputID);
  1049. handles = UpdatePLSrunSettings(handles);
  1050. guidata(hObject, handles);
  1051. %--- Executes on button press in CheckboxSingleBhv. ---%
  1052. %------------------------------------------------------%
  1053. function CheckboxSingleBhv_Callback(hObject, eventdata, handles)
  1054. handles = UpdatePLSrunSettings(handles);
  1055. guidata(hObject, handles);
  1056. %--- Executes on button press in CheckboxKeepDatamat. ---%
  1057. %--------------------------------------------------------%
  1058. function CheckboxKeepDatamat_Callback(hObject, eventdata, handles)
  1059. prompt = {'WARNING:';
  1060. 'Saving datamat will consume a large amount of HDD space.';
  1061. 'Are you sure you want to enable setting?'};
  1062. SaveDatamat = questdlg(prompt, 'WARNING:', 'YES', 'NO', 'NO');
  1063. if strcmp(SaveDatamat, 'NO')
  1064. set(handles.CheckboxKeepDatamat, 'Value', 0);
  1065. return;
  1066. end
  1067. handles = UpdatePLSrunSettings(handles);
  1068. guidata(hObject, handles);
  1069. %--- Executes on selection change in DropdownMCentType. ---%
  1070. %----------------------------------------------------------%
  1071. function DropdownMCentType_Callback(hObject, eventdata, handles)
  1072. handles = UpdatePLSrunSettings(handles);
  1073. guidata(hObject, handles);
  1074. %--- Executes on selection change in DropdownCorrMode. ---%
  1075. %---------------------------------------------------------%
  1076. function DropdownCorrMode_Callback(hObject, eventdata, handles)
  1077. handles = UpdatePLSrunSettings(handles);
  1078. guidata(hObject, handles);
  1079. %--- Executes on selection change in DropdownPermType. ---%
  1080. %---------------------------------------------------------%
  1081. function DropdownPermType_Callback(hObject, eventdata, handles)
  1082. handles = UpdatePLSrunSettings(handles);
  1083. guidata(hObject, handles);
  1084. %--- Executes on selection change in DropdownBootType. ---%
  1085. %---------------------------------------------------------%
  1086. function DropdownBootType_Callback(hObject, eventdata, handles)
  1087. handles = UpdatePLSrunSettings(handles);
  1088. guidata(hObject, handles);
  1089. %--- Updates PLSrun settings & GUI panel. ---%
  1090. %----------------------------------------------%
  1091. function OutputHandles = UpdatePLSrunSettings(InputHandles)
  1092. handles = InputHandles;
  1093. % Read GUI to update PLSrun settings:
  1094. DropdownOptions = get(handles.DropdownPLSMethod, 'String');
  1095. PLSMethod = DropdownOptions{get(handles.DropdownPLSMethod, 'Value')};
  1096. switch PLSMethod
  1097. case 'Mean-Centered'
  1098. handles.PLSrun.Method = 'MCENT';
  1099. case 'Non-Rotated'
  1100. handles.PLSrun.Method = 'NROT';
  1101. case 'Behavior/Seed'
  1102. handles.PLSrun.Method = 'BHV';
  1103. case 'Multi-Block'
  1104. handles.PLSrun.Method = 'MBLOCK';
  1105. case 'NRot. Behavior'
  1106. handles.PLSrun.Method = 'NR-BHV';
  1107. case 'NRot. Multi-Block'
  1108. handles.PLSrun.Method = 'NR-MBLOCK';
  1109. end
  1110. handles.PLSrun.NumPerm = str2num(get(handles.TextboxNumPermutations, 'String'));
  1111. handles.PLSrun.NumBoot = str2num(get(handles.TextboxNumBootstraps, 'String'));
  1112. handles.PLSrun.NumSplit = str2num(get(handles.TextboxNumSplits, 'String'));
  1113. handles.PLSrun.NRContrast = str2num(get(handles.TextboxNRContrast, 'String'));
  1114. handles.PLSrun.NRContrastID = get(handles.TextboxNRContrastID, 'String');
  1115. if get(handles.CheckboxKeepDatamat, 'Value') == 1
  1116. handles.PLSrun.KeepDatamat = 'yes';
  1117. else
  1118. handles.PLSrun.KeepDatamat = 'no';
  1119. end
  1120. if get(handles.CheckboxSplitHalfPLS, 'Value') == 1
  1121. handles.PLSrun.SplitHalf = 'yes';
  1122. else
  1123. handles.PLSrun.SplitHalf = 'no';
  1124. handles.PLSrun.NumSplit = 0;
  1125. end
  1126. if get(handles.CheckboxSingleBhv, 'Value') == 1 && ...
  1127. ismember(handles.PLSrun.Method, {'BHV', 'MBLOCK', 'NR-BHV', 'NR-MBLOCK'})
  1128. handles.PLSrun.SingleBhv = 'yes';
  1129. else
  1130. handles.PLSrun.SingleBhv = 'no';
  1131. end
  1132. DropdownOptions = get(handles.DropdownMCentType, 'String');
  1133. MCentType = DropdownOptions{get(handles.DropdownMCentType, 'Value')};
  1134. handles.PLSrun.MCentType = str2num(MCentType);
  1135. DropdownOptions = get(handles.DropdownCorrMode, 'String');
  1136. CorrMode = DropdownOptions{get(handles.DropdownCorrMode, 'Value')};
  1137. handles.PLSrun.CorrMode = str2num(CorrMode);
  1138. DropdownOptions = get(handles.DropdownPermType, 'String');
  1139. PermType = DropdownOptions{get(handles.DropdownPermType, 'Value')};
  1140. handles.PLSrun.PermType = str2num(PermType);
  1141. DropdownOptions = get(handles.DropdownBootType, 'String');
  1142. BootType = DropdownOptions{get(handles.DropdownBootType, 'Value')};
  1143. switch BootType
  1144. case 'stratified'
  1145. handles.PLSrun.BootType = 'strat';
  1146. case 'non-stratified'
  1147. handles.PLSrun.BootType = 'nonstrat';
  1148. otherwise
  1149. error('Unrecognized option.') % error-check
  1150. end
  1151. % Enable/disable GUI PLSrun components:
  1152. if get(handles.CheckboxRunPLS, 'Value') == 1
  1153. set(findall(handles.PanelPLSrunSettings, '-property', 'Enable'), 'Enable', 'on');
  1154. else
  1155. set(findall(handles.PanelPLSrunSettings, '-property', 'Enable'), 'Enable', 'off');
  1156. end
  1157. if ~ismember(handles.PLSrun.Method, {'MCENT', 'NROT', 'MBLOCK', 'NR-MBLOCK'})
  1158. set(handles.DropdownMCentType, 'Enable', 'off');
  1159. set(handles.TextMCentType, 'Enable', 'off');
  1160. end
  1161. if ~ismember(handles.PLSrun.Method, {'NROT', 'NR-BHV', 'NR-MBLOCK'})
  1162. set(handles.TextboxNRContrast, 'Enable', 'off');
  1163. set(handles.TextboxNRContrastID, 'Enable', 'off');
  1164. set(handles.TextNRContrastID, 'Enable', 'off');
  1165. end
  1166. if ~ismember(handles.PLSrun.Method, {'BHV', 'MBLOCK', 'NR-BHV', 'NR-MBLOCK'})
  1167. set(handles.CheckboxSingleBhv, 'Enable', 'off');
  1168. end
  1169. if get(handles.CheckboxSplitHalfPLS, 'Value') == 0
  1170. set(handles.TextboxNumSplits, 'Enable', 'off');
  1171. set(handles.TextNumSplits, 'Enable', 'off');
  1172. end
  1173. % Set output handles:
  1174. OutputHandles = handles;
  1175. %--- Reset PLSrun settings & GUI panel. ---%
  1176. %------------------------------------------%
  1177. function OutputHandles = ResetPLSrunSettings(InputHandles)
  1178. handles = InputHandles;
  1179. % Reset PLSrun settings:
  1180. handles.PLSrun.Method = 'MCENT';
  1181. handles.PLSrun.NumPerm = 500;
  1182. handles.PLSrun.NumBoot = 500;
  1183. handles.PLSrun.NumSplit = 0;
  1184. handles.PLSrun.NRContrast = [];
  1185. handles.PLSrun.NRContrastID = [];
  1186. handles.PLSrun.KeepDatamat = 'no';
  1187. handles.PLSrun.SplitHalf = 'no';
  1188. handles.PLSrun.SingleBhv = 'no';
  1189. handles.PLSrun.MCentType = 0;
  1190. handles.PLSrun.CorrMode = 0;
  1191. handles.PLSrun.PermType = 0;
  1192. handles.PLSrun.BootType = 'strat';
  1193. % Reset GUI PLSrun panel back to default:
  1194. DropdownOptions = get(handles.DropdownPLSMethod, 'String');
  1195. DropdownValue = find(strcmp(DropdownOptions, 'Mean-Centered'));
  1196. set(handles.DropdownPLSMethod, 'Value', DropdownValue);
  1197. if DropdownValue == 0
  1198. error('Option does not exist in dropdown list.'); % Error-check
  1199. end
  1200. set(handles.TextboxNumPermutations, 'String', num2str(500));
  1201. set(handles.TextboxNumBootstraps, 'String', num2str(500));
  1202. set(handles.TextboxNumSplits, 'String', num2str(0));
  1203. set(handles.TextboxNRContrast, 'String', []);
  1204. set(handles.TextboxNRContrastID, 'String', []);
  1205. set(handles.CheckboxSplitHalfPLS, 'Value', 0);
  1206. set(handles.CheckboxSingleBhv, 'Value', 0);
  1207. set(handles.CheckboxKeepDatamat, 'Value', 0);
  1208. set(handles.DropdownMCentType, 'Value', 1); % Sets type to 0.
  1209. set(handles.DropdownCorrMode, 'Value', 1); % Sets type to 0.
  1210. set(handles.DropdownPermType, 'Value', 1); % Sets type to 0.
  1211. DropdownOptions = get(handles.DropdownBootType, 'String');
  1212. DropdownValue = find(strcmp(DropdownOptions, 'stratified'));
  1213. set(handles.DropdownBootType, 'Value', DropdownValue);
  1214. if DropdownValue == 0
  1215. error('Option does not exist in dropdown list.'); % Error-check
  1216. end
  1217. % Set output handles:
  1218. OutputHandles = handles;
  1219. %=====================================%
  1220. % GUI FUNCTIONS FOR RUNNING ANALYSIS: %
  1221. %=====================================%
  1222. %--- Executes on button press in ButtonStartAnalysis. ---%
  1223. %--------------------------------------------------------%
  1224. function ButtonStartAnalysis_Callback(hObject, eventdata, handles)
  1225. % Check for errors and required settings:
  1226. if isempty(handles.gui.BuilderMat)
  1227. msgbox('ERROR: Builder .mat file has not been loaded yet.', 'Error:')
  1228. return;
  1229. end
  1230. if get(handles.CheckboxMakePLSmat, 'Value') == 1
  1231. if isempty(handles.PLSmat.SessionID)
  1232. msgbox('ERROR: Enter SessionID for PLS run.', 'Error:')
  1233. return;
  1234. end
  1235. if isempty(handles.PLSmat.TimeIndices)
  1236. msgbox('ERROR: Specify AFNI time-indices for PLS.', 'Error:')
  1237. return;
  1238. end
  1239. if ismember(handles.PLSrun.Method, {'BHV', 'MBLOCK', 'NR-BHV', 'NR-MBLOCK'})
  1240. if isempty(handles.PLSmat.BhvFile) && isempty(handles.PLSmat.SeedFile)
  1241. msgbox('ERROR: Select behavior and/or seed .xls files.')
  1242. return;
  1243. end
  1244. if isempty(handles.PLSmat.BhvSeedID)
  1245. msgbox('ERROR: Enter ID for behavior and/or seeds selected.')
  1246. return;
  1247. end
  1248. end
  1249. end
  1250. if get(handles.CheckboxRunPLS, 'Value') == 1
  1251. if isempty(get(handles.TextboxNumPermutations, 'String'))
  1252. msgbox('Error: Number of permutations not specified.', 'Error:');
  1253. return;
  1254. end
  1255. if isempty(get(handles.TextboxNumBootstraps, 'String'))
  1256. msgbox('Error: Number of bootstraps not specified.', 'Error:');
  1257. return;
  1258. end
  1259. if isempty(get(handles.TextboxNumSplits, 'String')) && ...
  1260. get(handles.CheckboxSplitHalfPLS, 'Value') == 1
  1261. msgbox('Error: Number of splits not specified.', 'Error:');
  1262. return;
  1263. end
  1264. if ismember(handles.PLSrun.Method, {'NROT', 'NR-BHV', 'NR-MBLOCK'})
  1265. if isempty(handles.PLSrun.NRContrast) || isempty(handles.PLSrun.NRContrastID)
  1266. msgbox('ERROR: Enter NR Contrast & Contrast ID.')
  1267. return;
  1268. end
  1269. end
  1270. end
  1271. % Ask user to confirm:
  1272. ConfirmRun = questdlg('CONFIRM: Start analysis with current settings?',...
  1273. 'CONFIRM:', 'YES', 'NO', 'NO');
  1274. if strcmp(ConfirmRun, 'NO')
  1275. return;
  1276. end
  1277. % Check for Matlab PCT:
  1278. CheckOpenPCT
  1279. commandwindow;
  1280. % Run timelock and/or frequency analysis:
  1281. if get(handles.CheckboxTimelockAnalysis, 'Value') == 1
  1282. MEGpipeline_TimelockFreq (handles.gui.BuilderMat, 'Timelock')
  1283. end
  1284. if get(handles.CheckboxTimelockGrpAvg, 'Value') == 1
  1285. MEGpipeline_TimelockFreqAvg (handles.gui.BuilderMat, 'Timelock')
  1286. end
  1287. if get(handles.CheckboxFreqAnalysis, 'Value') == 1
  1288. MEGpipeline_TimelockFreq (handles.gui.BuilderMat, 'Freq')
  1289. end
  1290. if get(handles.CheckboxFreqGrpAvg, 'Value') == 1
  1291. MEGpipeline_TimelockFreqAvg (handles.gui.BuilderMat, 'Freq')
  1292. end
  1293. % Run seg, headmodels & leadfields:
  1294. if get(handles.CheckboxSegmentMRI, 'Value') == 1
  1295. MEGpipeline_SegmentMRI(handles.gui.BuilderMat)
  1296. end
  1297. if get(handles.CheckboxHdmLeadfield, 'Value') == 1
  1298. MEGpipeline_HdmLeadfield(handles.gui.BuilderMat)
  1299. end
  1300. % Run source analysis sections:
  1301. if get(handles.CheckboxSourceFilter, 'Value') == 1
  1302. MEGpipeline_SourceFilter_Wrap(handles.gui.BuilderMat)
  1303. end
  1304. if get(handles.CheckboxSourceAnalysis, 'Value') == 1
  1305. MEGpipeline_SourceAnalysis_Wrap(handles.gui.BuilderMat)
  1306. end
  1307. if get(handles.CheckboxMakeSourceNifti, 'Value') == 1
  1308. MEGpipeline_MakeInterpSourceNii_Wrap (handles.gui.BuilderMat)
  1309. MEGpipeline_MakeMRINii_Wrap (handles.gui.BuilderMat, 'PreprocMRI')
  1310. end
  1311. if get(handles.CheckboxMakeSourceAfni, 'Value') == 1
  1312. MEGpipeline_Nifti4DFunc2AFNI_Wrap (handles.gui.BuilderMat, 'Nifti4DSource')
  1313. MEGpipeline_NiftiAnat2AFNI_Wrap (handles.gui.BuilderMat, 'PreprocMRINii')
  1314. end
  1315. % Run normalise source sections:
  1316. if get(handles.CheckboxNormaliseSource, 'Value') == 1
  1317. MEGpipeline_NormaliseSPM_Wrap(handles.gui.BuilderMat)
  1318. end
  1319. if get(handles.CheckboxMakeNormSrcNifti, 'Value') == 1
  1320. MEGpipeline_MakeNormSourceNii_Wrap (handles.gui.BuilderMat)
  1321. MEGpipeline_MakeMRINii_Wrap (handles.gui.BuilderMat, 'NormMRI')
  1322. end
  1323. if get(handles.CheckboxMakeNormSrcAfni, 'Value') == 1
  1324. MEGpipeline_Nifti4DFunc2AFNI_Wrap (handles.gui.BuilderMat, 'Nifti4DNormSource')
  1325. MEGpipeline_NiftiAnat2AFNI_Wrap (handles.gui.BuilderMat, 'NormMRINii')
  1326. end
  1327. % Run group-average normsource sections:
  1328. if get(handles.CheckboxGroupAvgNormSrc, 'Value') == 1
  1329. MEGpipeline_SourceAvg(handles.gui.BuilderMat)
  1330. end
  1331. if get(handles.CheckboxMakeGrpAvgNifti, 'Value') == 1
  1332. MEGpipeline_MakeGrpAvgNii_Wrap(handles.gui.BuilderMat)
  1333. end
  1334. if get(handles.CheckboxMakeGrpAvgAfni, 'Value') == 1
  1335. MEGpipeline_Nifti4DFunc2AFNI_Wrap(handles.gui.BuilderMat, 'Nifti4DGrpAvg')
  1336. end
  1337. % Run PLS sections:
  1338. if get(handles.CheckboxMakePLSmat, 'Value') == 1
  1339. InputPLSmat = handles.PLSmat;
  1340. if strcmp(InputPLSmat.MaskType, 'BrainMask')
  1341. if strcmp(InputPLSmat.DataSpecificMask, 'yes')
  1342. InputPLSmat.BrainMaskFile = [];
  1343. InputPLSmat.ROIMaskFile = [];
  1344. else
  1345. InputPLSmat.ROIMaskFile = [];
  1346. end
  1347. elseif strcmp(InputPLSmat.MaskType, 'ROIMask')
  1348. InputPLSmat.BrainMaskFile = [];
  1349. end
  1350. PLSmatReady = MEGpipeline_MakePLSmat(InputPLSmat)
  1351. InputPLSmat = []; % Free memory
  1352. if get(handles.CheckboxRunPLS, 'Value') == 0
  1353. msgbox('Debug: Checking datamat without running PLS. Activating keyboard mode.')
  1354. PLSmatReady
  1355. keyboard;
  1356. end
  1357. end
  1358. if get(handles.CheckboxRunPLS, 'Value') == 1
  1359. MEGpipeline_RunPLS(PLSmatReady, handles.PLSrun)
  1360. end
  1361. %=================================%
  1362. % FUNCTION TO OPEN MODAL WAITBOX: %
  1363. %=================================%
  1364. function WaitBox = StartWaitBox(TextString)
  1365. WaitBox = dialog('Units', 'pixels', 'Position', [500 500 300 40],...
  1366. 'Windowstyle', 'modal', 'NextPlot', 'new', 'Name', 'Please Wait:');
  1367. uicontrol('Parent', WaitBox, 'Units', 'pixels', 'Position', [20 10 250 20],...
  1368. 'Style', 'text', 'String', TextString, 'FontWeight', 'bold');
  1369. movegui(WaitBox, 'center');
  1370. %==============================%
  1371. % GUIDE "CREATEFCN" FUNCTIONS: %
  1372. %==============================%
  1373. % --- Executes during object creation, after setting all properties.
  1374. function TextboxBuilderMat_CreateFcn(hObject, eventdata, handles)
  1375. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1376. set(hObject,'BackgroundColor','white');
  1377. end
  1378. % --- Executes during object creation, after setting all properties.
  1379. function ListboxPLSmatGroupID_CreateFcn(hObject, eventdata, handles)
  1380. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1381. set(hObject,'BackgroundColor','white');
  1382. end
  1383. % --- Executes during object creation, after setting all properties.
  1384. function ListboxPLSmatSubjID_CreateFcn(hObject, eventdata, handles)
  1385. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1386. set(hObject,'BackgroundColor','white');
  1387. end
  1388. % --- Executes during object creation, after setting all properties.
  1389. function ListboxPLSmatCondID_CreateFcn(hObject, eventdata, handles)
  1390. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1391. set(hObject,'BackgroundColor','white');
  1392. end
  1393. % --- Executes during object creation, after setting all properties.
  1394. function TextboxBrainMaskFile_CreateFcn(hObject, eventdata, handles)
  1395. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1396. set(hObject,'BackgroundColor','white');
  1397. end
  1398. % --- Executes during object creation, after setting all properties.
  1399. function TextboxKeepVoxelThresh_CreateFcn(hObject, eventdata, handles)
  1400. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1401. set(hObject,'BackgroundColor','white');
  1402. end
  1403. % --- Executes during object creation, after setting all properties.
  1404. function TextboxROIMaskFile_CreateFcn(hObject, eventdata, handles)
  1405. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1406. set(hObject,'BackgroundColor','white');
  1407. end
  1408. % --- Executes during object creation, after setting all properties.
  1409. function TextboxROISize_CreateFcn(hObject, eventdata, handles)
  1410. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1411. set(hObject,'BackgroundColor','white');
  1412. end
  1413. % --- Executes during object creation, after setting all properties.
  1414. function SliderTimeStartPLS_CreateFcn(hObject, eventdata, handles)
  1415. if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1416. set(hObject,'BackgroundColor',[.9 .9 .9]);
  1417. end
  1418. % --- Executes during object creation, after setting all properties.
  1419. function SliderTimeEndPLS_CreateFcn(hObject, eventdata, handles)
  1420. if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1421. set(hObject,'BackgroundColor',[.9 .9 .9]);
  1422. end
  1423. % --- Executes during object creation, after setting all properties.
  1424. function TextboxTimeStartPLS_CreateFcn(hObject, eventdata, handles)
  1425. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1426. set(hObject,'BackgroundColor','white');
  1427. end
  1428. % --- Executes during object creation, after setting all properties.
  1429. function TextboxTimeEndPLS_CreateFcn(hObject, eventdata, handles)
  1430. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1431. set(hObject,'BackgroundColor','white');
  1432. end
  1433. % --- Executes during object creation, after setting all properties.
  1434. function ListboxManualTimeSelect_CreateFcn(hObject, eventdata, handles)
  1435. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1436. set(hObject,'BackgroundColor','white');
  1437. end
  1438. % --- Executes during object creation, after setting all properties.
  1439. function TextboxBhvSeedID_CreateFcn(hObject, eventdata, handles)
  1440. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1441. set(hObject,'BackgroundColor','white');
  1442. end
  1443. % --- Executes during object creation, after setting all properties.
  1444. function TextboxBhvFile_CreateFcn(hObject, eventdata, handles)
  1445. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1446. set(hObject,'BackgroundColor','white');
  1447. end
  1448. % --- Executes during object creation, after setting all properties.
  1449. function TextboxSeedFile_CreateFcn(hObject, eventdata, handles)
  1450. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1451. set(hObject,'BackgroundColor','white');
  1452. end
  1453. % --- Executes during object creation, after setting all properties.
  1454. function TextboxSeedSize_CreateFcn(hObject, eventdata, handles)
  1455. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1456. set(hObject,'BackgroundColor','white');
  1457. end
  1458. % --- Executes during object creation, after setting all properties.
  1459. function TextboxPLSmatSessionID_CreateFcn(hObject, eventdata, handles)
  1460. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1461. set(hObject,'BackgroundColor','white');
  1462. end
  1463. % --- Executes during object creation, after setting all properties.
  1464. function DropdownPLSMethod_CreateFcn(hObject, eventdata, handles)
  1465. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1466. set(hObject,'BackgroundColor','white');
  1467. end
  1468. % --- Executes during object creation, after setting all properties.
  1469. function TextboxNumPermutations_CreateFcn(hObject, eventdata, handles)
  1470. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1471. set(hObject,'BackgroundColor','white');
  1472. end
  1473. % --- Executes during object creation, after setting all properties.
  1474. function TextboxNumBootstraps_CreateFcn(hObject, eventdata, handles)
  1475. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1476. set(hObject,'BackgroundColor','white');
  1477. end
  1478. % --- Executes during object creation, after setting all properties.
  1479. function TextboxNumSplits_CreateFcn(hObject, eventdata, handles)
  1480. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1481. set(hObject,'BackgroundColor','white');
  1482. end
  1483. % --- Executes during object creation, after setting all properties.
  1484. function TextboxNRContrast_CreateFcn(hObject, eventdata, handles)
  1485. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1486. set(hObject,'BackgroundColor','white');
  1487. end
  1488. % --- Executes during object creation, after setting all properties.
  1489. function TextboxNRContrastID_CreateFcn(hObject, eventdata, handles)
  1490. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1491. set(hObject,'BackgroundColor','white');
  1492. end
  1493. % --- Executes during object creation, after setting all properties.
  1494. function DropdownMCentType_CreateFcn(hObject, eventdata, handles)
  1495. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1496. set(hObject,'BackgroundColor','white');
  1497. end
  1498. % --- Executes during object creation, after setting all properties.
  1499. function DropdownCorrMode_CreateFcn(hObject, eventdata, handles)
  1500. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1501. set(hObject,'BackgroundColor','white');
  1502. end
  1503. % --- Executes during object creation, after setting all properties.
  1504. function DropdownPermType_CreateFcn(hObject, eventdata, handles)
  1505. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1506. set(hObject,'BackgroundColor','white');
  1507. end
  1508. % --- Executes during object creation, after setting all properties.
  1509. function DropdownBootType_CreateFcn(hObject, eventdata, handles)
  1510. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1511. set(hObject,'BackgroundColor','white');
  1512. end